# 自己的双指针解法：费了很大力气，老是越界。总结，在使用下标的时候一定要加越界判断
class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        skey, tkey = 0, 0
        tlen = len(t)
        slen = len(s)
        while True:
            if skey < slen and tkey < tlen:
                if s[skey] == t[tkey]:  # 在这句之前一定要加判断
                    skey += 1
                    tkey += 1
                else:
                    tkey += 1
            if skey == slen:
                return True
            elif tkey == tlen:
                return False

# 官方的代码老简单了，狗头


class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        n, m = len(s), len(t)
        i = j = 0
        while i < n and j < m:
            if s[i] == t[j]:
                i += 1
            j += 1
        return i == n

# 作者：LeetCode-Solution
# 链接：https://leetcode-cn.com/problems/is-subsequence/solution/pan-duan-zi-xu-lie-by-leetcode-solution/
# 来源：力扣（LeetCode）
# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。

# 官方还给出了动态规划的例子，效率更高，但更难